#!/bin/sh
# $Id: alert 3302 2010-08-09 18:39:20Z eldering $

# This script will be called by different parts of the DOMjudge system
# and allows the administrator to flexibly configure a way to get
# notified of important messages. By default this script calls 'beep'
# if available.

# Calling syntax: $0 <msgtype> [<description>]

MSGTYPE=$1
if [ -z "$MSGTYPE" ]; then
	echo "Error: missing required message type argument."
	exit 1
fi

shift
DESCRIPTION="$@"

BEEPCMD=`which beep`

beep()
{
	[ -x "$BEEPCMD" ] && $BEEPCMD $@
}

case "$MSGTYPE" in
	error) # internal system error
		beep "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000 -n " \
		     "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000 -n " \
		     "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000 -n " \
		     "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000 -n " \
		     "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000"
		;;

	warning) # important system warning
		beep "-l 1000 -d 500 -f 300 -n -l 1000 -d 500 -f 200 -n " \
		     "-l 1000 -d 500 -f 300 -n -l 1000 -d 500 -f 200"
		;;

	usererr) # user error
		beep "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000 -n " \
		     "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000 -n " \
		     "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000 -n " \
		     "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000 -n " \
		     "-l 1000 -d 500 -f 800 -n -l 1000 -d 500 -f 1000"
		;;

	submit) # team submission received
		beep "-f 400 -l 100 -n -f 400 -l 70"
		;;

	accept) # submission judged and accepted
		beep "-f 400 -l 100 -n -f 500 -l 70"
		;;

	reject) # submission judged and rejected
		beep "-f 400 -l 100 -n -f 350 -l 70"
		;;

	*)
		echo "Error: unknown message type '$MSGTYPE' specified."
		exit 1
		;;
esac
